package com.seqb.manage.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.seqb.common.mybatis.WrapperHandler;
import com.seqb.manage.user.dao.UserSubjectDao;
import com.seqb.manage.user.domain.UserSubjectDO;
import com.seqb.manage.user.service.UserSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.Map;

/**
 * @author lilinshen
 * @title 用户科目表
 * @description 请填写相关描述
 * @date 2019-12-04
 */
@Service
public class UserSubjectServiceImpl implements UserSubjectService {
    @Autowired
    private UserSubjectDao userSubjectDao;

    @Override
    public UserSubjectDO get(Long id) {
        return userSubjectDao.selectById(id);
    }

    @Override
    public Page<UserSubjectDO> list(Map<String, Object> map) {
        if (null != map && null != map.get("pageNumber") && null != map.get("pageSize")) {
            PageHelper.startPage(Integer.valueOf(map.get("pageNumber").toString()), Integer.valueOf(map.get("pageSize").toString()));
        } else {
            PageHelper.startPage(1, Integer.MAX_VALUE);
        }
        QueryWrapper queryWrapper = WrapperHandler.genQueryWrapper(map, UserSubjectDO.class);
        return (Page<UserSubjectDO>) userSubjectDao.selectList(queryWrapper);
    }

    @Override
    public int count(Map<String, Object> map) {
        QueryWrapper queryWrapper = WrapperHandler.genQueryWrapper(map, UserSubjectDO.class);
        return userSubjectDao.selectCount(queryWrapper);
    }

    @Override
    @Transactional
    public int save(UserSubjectDO userSubject) {
        return userSubjectDao.insert(userSubject);
    }

    @Override
    @Transactional
    public int update(UserSubjectDO userSubject) {
        return userSubjectDao.updateById(userSubject);
    }

    @Override
    @Transactional
    public int remove(Long id) {
        return userSubjectDao.deleteById(id);
    }

    @Override
    @Transactional
    public int batchRemove(Long[] ids) {
        return userSubjectDao.deleteBatchIds(Arrays.asList(ids));
    }

}
